package com.lsy.weizhi2.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lsy.weizhi2.R;
import com.lsy.weizhi2.picture.BucketDisplay;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by 嗨哟 on 2016/12/16.
 */
public class MyAblum_Adapter extends BaseAdapter {
    private Context context;
    private List<BucketDisplay> list_ablum;
    private LayoutInflater inflater;
    public MyAblum_Adapter(Context context, List<BucketDisplay> list_ablum) {
        this.context = context;
        this.list_ablum = list_ablum;
        inflater=LayoutInflater.from(context);
    }
    public void UpData(List list){
        this.list_ablum=list;
        this.notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return list_ablum==null?0:list_ablum.size();
    }

    @Override
    public Object getItem(int i) {
        return list_ablum.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            viewHolder=new ViewHolder();
            view=inflater.inflate(R.layout.ablum_grid_item,viewGroup,false);
            viewHolder.album_iv= (ImageView) view.findViewById(R.id.album_iv);
            viewHolder.ablum_classify_info= (TextView) view.findViewById(R.id.ablum_classify_info);
            view.setTag(viewHolder);
            AutoUtils.autoSize(view);
        }
        viewHolder= (ViewHolder) view.getTag();
        Log.i("MyAblumAdapter","FirstUrl=="+list_ablum.get(i).getFirstUrl());
        Glide.with(context).load(list_ablum.get(i).getFirstUrl()).into(viewHolder.album_iv);
        viewHolder.ablum_classify_info.setText(list_ablum.get(i).getName()+"(共"+list_ablum.get(i).getCount()+"张)");
        return view;
    }
    class ViewHolder {
        ImageView album_iv;
        TextView ablum_classify_info;
    }
}
